//
//  PredetermineViewCell.m
//  TravelFollowYourHeart
//
//  Created by ENERGY on 2017/12/21.
//  Copyright © 2017年 Lwx. All rights reserved.
//

#import "PredetermineViewCell.h"
#define border 10

@interface PredetermineViewCell ()

@property (nonatomic, strong)UIView * bgView;
@property (nonatomic, strong)UILabel * orderNumLab;
@property (nonatomic, strong)UILabel * dateLab;
@property (nonatomic, strong)UIView * lineView;
@property (nonatomic, strong)UIImageView * cornImage;
@property (nonatomic, strong)UILabel * titleLab;
@property (nonatomic, strong)UILabel * moneyLab;
@property (nonatomic, strong)UIButton * checkOrderBtn;
@property (nonatomic, strong)UILabel * advanceepositLab;
@property (nonatomic, strong)UILabel * advanceepositMoneyLab;
@property (nonatomic, strong)UIButton * finishiBtn;
@property (nonatomic, strong)UIButton * unfinishiBtn;
@property (nonatomic, strong)UIButton * evaluateBtn;
@property (nonatomic, strong)NSString * is_evaluate;
@property (nonatomic, strong)NSString * activityID;//活动或信息ID
@end

@implementation PredetermineViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.backgroundColor = getColor(bgColor);
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self.contentView addSubview:self.bgView];
        [self.bgView addSubview:self.dateLab];
        [self.bgView addSubview:self.orderNumLab];
        [self.bgView addSubview:self.lineView];
        [self.bgView addSubview:self.cornImage];
        [self.bgView addSubview:self.titleLab];
        [self.bgView addSubview:self.moneyLab];
        [self.bgView addSubview:self.checkOrderBtn];
        [self.bgView addSubview:self.advanceepositLab];
        [self.bgView addSubview:self.advanceepositMoneyLab];
        [self.bgView addSubview:self.finishiBtn];
        [self.bgView addSubview:self.unfinishiBtn];
        [self.bgView addSubview:self.evaluateBtn];
        
    }return self;
}

- (UIView *)bgView{
    if (!_bgView) {
//        _bgView = [[UIView alloc] initWithFrame:CGRectMake(0, border, SCREEN_WIDTH, self.contentView.height)];
        _bgView = [[UIView alloc] init];
        _bgView.backgroundColor = [UIColor whiteColor];
        
    }return _bgView;
}

- (UILabel *)dateLab{
    if (!_dateLab) {
        _dateLab = [[UILabel alloc] init];
        _dateLab.text = @"2017-01-01 11：11";
        _dateLab.font = DEF_FontSize_14;
        _dateLab.textAlignment = NSTextAlignmentLeft;
//        _dateLab.backgroundColor = [UIColor orangeColor];

    }return _dateLab;
}

- (UILabel *)orderNumLab{
    if (!_orderNumLab) {
        _orderNumLab = [[UILabel alloc] init];
        _orderNumLab.text = @"02.单号XXXXXXXXX";
        _orderNumLab.textAlignment = NSTextAlignmentLeft;
        _orderNumLab.font = DEF_FontSize_14;
//        _orderNumLab.backgroundColor = [UIColor greenColor];

    }return _orderNumLab;
}

- (UIView *)lineView{
    if (!_lineView) {
        _lineView = [[UIView alloc] init];
        _lineView.backgroundColor = getColor(bgColor);
//        _lineView.layer.borderWidth = 1;
        
    }return _lineView;
}

- (UIImageView *)cornImage{
    if (!_cornImage) {
        _cornImage = [[UIImageView alloc] init];
        _cornImage.image = [UIImage imageNamed:@"img_list2111"];
    }return _cornImage;
}

- (UILabel *)titleLab{
    if (!_titleLab) {
        _titleLab = [[UILabel alloc] init];
        _titleLab.text = @"填写的是预定的地点";
        _titleLab.font = DEF_FontSize_14;
    }return _titleLab;
}

- (UILabel *)moneyLab{
    if (!_moneyLab) {
        _moneyLab = [[UILabel alloc] init];
        _moneyLab.text = @"￥2300";
        _moneyLab.font = DEF_FontSize_14;
//        _moneyLab.backgroundColor = [UIColor purpleColor];
    }return _moneyLab;
}

- (UIButton *)checkOrderBtn{
    if (!_checkOrderBtn) {
        _checkOrderBtn = [[UIButton alloc] init];
        [_checkOrderBtn setTitle:@"查看预订单" forState:UIControlStateNormal];
        [_checkOrderBtn setTitleColor:getColor(@"ffbb02") forState:UIControlStateNormal];
        [_checkOrderBtn setBackgroundColor:[UIColor clearColor]];
        _checkOrderBtn.titleLabel.font = DEF_FontSize_14;
        [_checkOrderBtn addTarget:self action:@selector(checkBtnClick) forControlEvents:UIControlEventTouchUpInside];
    }return _checkOrderBtn;
}

- (UILabel *)advanceepositLab{
    if (!_advanceepositLab) {
        _advanceepositLab = [[UILabel alloc] init];
        _advanceepositLab.text = @"预定金";
        _advanceepositLab.font = DEF_FontSize_14;
//        _advanceepositLab.backgroundColor = [UIColor yellowColor];
    }return _advanceepositLab;
}

- (UILabel *)advanceepositMoneyLab{
    if (!_advanceepositMoneyLab) {
        _advanceepositMoneyLab = [[UILabel alloc] init];
        _advanceepositMoneyLab.text = @"￥25";
        _advanceepositMoneyLab.font = DEF_FontSize_14;
        _advanceepositMoneyLab.textColor = [UIColor redColor];
//        _advanceepositMoneyLab.backgroundColor = [UIColor blueColor];
    }return _advanceepositMoneyLab;
}

- (UIButton *)finishiBtn{
    if (!_finishiBtn) {
        _finishiBtn = [[UIButton alloc] init];
        [_finishiBtn setTitle:@"已完成" forState:UIControlStateNormal];
        [_finishiBtn setTitleColor:getColor(@"ffbb02") forState:UIControlStateNormal];
        _finishiBtn.titleLabel.font = DEF_FontSize_14;
    }return _finishiBtn;
}

- (UIButton *)unfinishiBtn{
    if (!_unfinishiBtn) {
        _unfinishiBtn = [[UIButton alloc] init];
        [_unfinishiBtn setTitle:@"待完成" forState:UIControlStateNormal];
        [_unfinishiBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        _unfinishiBtn.titleLabel.font = DEF_FontSize_14;
    }return _unfinishiBtn;
}

- (UIButton *)evaluateBtn{
    if (!_evaluateBtn) {
        _evaluateBtn = [[UIButton alloc] init];
        [_evaluateBtn setCornerRadius:8];
        [_evaluateBtn setTitleColor:getColor(@"ffbb02") forState:UIControlStateNormal];
        _evaluateBtn.layer.borderWidth = 1;
        _evaluateBtn.layer.borderColor = getColor(@"ffbb02").CGColor;
        [_evaluateBtn setTitle:@"立即评价" forState:UIControlStateNormal];
        _evaluateBtn.titleLabel.font = DEF_FontSize_14;
        [_evaluateBtn addTarget:self action:@selector(evaluateBtnClick) forControlEvents:UIControlEventTouchUpInside];
    }return _evaluateBtn;
}

- (void)layoutSubviews{
    [super layoutSubviews];
    int dateLabW = 125;
    int labH = 20;
    int cornImageW = 80;
    int moneyLabW = 100;
    int checkBtnW = 80;
    int advanceepositLabW = 50;
    int advanceepositMoneyLabW = 70;
    int performanceBtnW = 50;
    int titleLabW = SCREEN_WIDTH - 4 * border - cornImageW - performanceBtnW;

    _bgView.frame = CGRectMake(0, border, SCREEN_WIDTH, self.contentView.height - border);
    _dateLab.frame = CGRectMake(SCREEN_WIDTH - dateLabW, 0, dateLabW, labH);
    _orderNumLab.frame = CGRectMake(border, 0, SCREEN_WIDTH - dateLabW - border * 2, labH);
    _lineView.frame = CGRectMake(0, _orderNumLab.bottom, SCREEN_WIDTH, 1);
    _cornImage.frame = CGRectMake(_orderNumLab.left, _lineView.bottom + border, cornImageW, cornImageW);
    _finishiBtn.frame = CGRectMake(SCREEN_WIDTH - performanceBtnW - border, _cornImage.top, performanceBtnW, labH);
    _unfinishiBtn.frame = CGRectMake(SCREEN_WIDTH - performanceBtnW - border, _cornImage.top, performanceBtnW, labH);
    _titleLab.frame = CGRectMake(_cornImage.right + border, _cornImage.top, titleLabW, labH);
    _moneyLab.frame = CGRectMake(_titleLab.left, _titleLab.bottom + border, moneyLabW, labH);
    _checkOrderBtn.frame = CGRectMake(_titleLab.left, _moneyLab.bottom + border, checkBtnW, labH);
    _advanceepositLab.frame = CGRectMake(_titleLab.left, _checkOrderBtn.bottom + border, advanceepositLabW, labH);
    _advanceepositMoneyLab.frame = CGRectMake(_advanceepositLab.right, _advanceepositLab.top, advanceepositMoneyLabW, labH);
    _evaluateBtn.frame = CGRectMake(self.finishiBtn.left - 20, self.checkOrderBtn.center.y, self.finishiBtn.width + 20, self.finishiBtn.height + 10);
}

- (void)checkBtnClick{
    if ([self.delegate respondsToSelector:@selector(checkBtnClickToNextPage:)]) {
        [self.delegate checkBtnClickToNextPage:self.activityID];
    }
    
}

- (void)evaluateBtnClick{
//    NSLog(@"立即评价");
    if ([self.delegate respondsToSelector:@selector(evaluateBtnClickToNextPage)]) {
        [self.delegate evaluateBtnClickToNextPage];
    }
}

- (void)setModelData:(PredetermineModelData *)modelData{
    _modelData = modelData;
    self.finishiBtn.hidden = YES;
    self.unfinishiBtn.hidden = YES;
    self.evaluateBtn.hidden = YES;
    self.evaluateBtn.userInteractionEnabled = YES;
    self.dateLab.text = modelData.addtime;
    self.orderNumLab.text = [NSString stringWithFormat:@"%@.单号%@", modelData.listId, modelData.number];
    self.titleLab.text = modelData.message;
    self.moneyLab.text = [NSString stringWithFormat:@"￥%@", modelData.price];
    self.advanceepositMoneyLab.text = [NSString stringWithFormat:@"￥%@", modelData.deposit];
    [self.cornImage sd_setImageWithURL:[NSURL URLWithString:modelData.pic]];
//    if ([modelData.type isEqualToString:@"2"]) {
//        self.evaluateBtn.hidden = YES;
//    }else if ([modelData.state isEqualToString:@"待完成"]){
//        self.evaluateBtn.hidden = YES;
//        self.finishiBtn.hidden = YES;
//        self.unfinishiBtn.hidden = NO;
//    }else if ([modelData.state isEqualToString:@"已完成"]){
//        self.evaluateBtn.hidden = NO;
//        self.finishiBtn.hidden = NO;
//        self.unfinishiBtn.hidden = YES;
//    }
    if ([modelData.type isEqualToString:@"2"]) {
        self.evaluateBtn.hidden = YES;
    }
    if ([modelData.state isEqualToString:@"待完成"]){
        self.evaluateBtn.hidden = YES;
        self.finishiBtn.hidden = YES;
        self.unfinishiBtn.hidden = NO;
    }else if ([modelData.state isEqualToString:@"已完成"]){
        self.evaluateBtn.hidden = NO;
        self.finishiBtn.hidden = NO;
        self.unfinishiBtn.hidden = YES;
    }
    if ([modelData.type isEqualToString:@"1"]) {
        if ([modelData.is_evaluate isEqualToString:@"已评价"]) {
            [self.evaluateBtn setTitle:@"已评价" forState:UIControlStateNormal];
            self.evaluateBtn.userInteractionEnabled = NO;
        }if ([modelData.is_evaluate isEqualToString:@"未评价"]) {
            [self.evaluateBtn setTitle:@"立即评价" forState:UIControlStateNormal];
        }
    }
    self.activityID = modelData.listId;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
